package JDBC;
// INSERT
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo2 {
    public static void main(String[] args) throws Exception {
        /*
         * 使用JDBC链接书库并操作的基本流成
         * */
        //1
        Class.forName("com.mysql.cj.jdbc.Driver");
        //2
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                "root", "root");
        System.out.println("成功链接数据库");
//成功链接数据库
        Statement statement = connection.createStatement();


        String sql = "INSERT INTO userinfo (username,password,nickname,age) " +
                "VALUE ('张三lll','123456','lll哥',20) ";

        int num = statement.executeUpdate(sql);

        if (num > 0) {
            System.out.println("插入完毕!");
        }
        connection.close();
    }
}
